package com.gupao.micro.services.mvc;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.support.DefaultTransactionStatus;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import com.gupao.micro.services.mvc.service.EchoService;

/**  
 * @Title: SpringApplication.java
 * @Description: TODO(用一句话描述该文件做什么)
 * @date 2018年8月16日 上午2:19:15
 * @version V1.0  
 */
@ComponentScan(basePackages="com.gupao.micro.services.mvc.service")
@EnableTransactionManagement //这个我没运行出效果
//@EnableWebMvc
public class SpringApplication {
	
	@Component
	public static class MyPlatformTransactionManager implements PlatformTransactionManager{

		@Override
		public void commit(TransactionStatus status) throws TransactionException {
			System.out.println("commit ..... ....");
		}

		@Override
		public TransactionStatus getTransaction(TransactionDefinition difinition) throws TransactionException {
			return new DefaultTransactionStatus(null, true, true, difinition.isReadOnly(), true, null);
		}

		@Override
		public void rollback(TransactionStatus arg0) throws TransactionException {
			System.out.println("rollback ..... ....");
		}
		
	}
	
	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
		//注册SpringApplication扫描 com.gupao.micro.services.mvc.service
		context.register(SpringApplication.class);
		
		context.refresh();//启动
		
		context.getBeansOfType(EchoService.class).forEach((beanName, bean) ->{
			System.err.println("Bean Name: " + beanName + " , Bean: " + bean);
		});
		
		context.close();//关闭
	}
}
